package com.np.adapterdemo1;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleAdapterActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.activity_simple_adapter, new String[]{"title", "img"}, new int[]{R.id.title, R.id.img});
        setListAdapter(adapter);
    }

    private List<Map<String, Object>> getData() {
        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, Object> map = new HashMap<>();
        map.put("title", "华为");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        map = new HashMap<>();
        map.put("title", "苹果");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        map = new HashMap<>();
        map.put("title", "三星");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        return list;
    }
}